package cn.initcap.bio.point2point.server;

import cn.initcap.bio.udp.search.constants.TcpConstants;
import cn.initcap.bio.udp.search.server.UdpProvider;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author initcap
 * @date Created in 5/1/19 3:52 PM.
 */
public class Server {

    public static void main(String[] args) throws IOException {
        TcpServer tcpServer = new TcpServer(TcpConstants.PORT_SERVER);
        boolean isSucceed = tcpServer.start();
        if (!isSucceed) {
            System.out.println("Start TCP server failed!");
            return;
        }

        UdpProvider.start(TcpConstants.PORT_SERVER);

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String str;
        do {
            str = bufferedReader.readLine();
            tcpServer.broadcast(str);
        } while (!"00bye00".equalsIgnoreCase(str));

        UdpProvider.stop();
        tcpServer.stop();
    }

}
